//
//  OpenCourseListViewController.m
//  xpkc
//
//  Created by TopSage on 15/9/30.
//  Copyright (c) 2015年 TopSage. All rights reserved.
//

#import "OpenCourseListViewController.h"

@interface OpenCourseListViewController (){
    UITableView *courseTable;
    NSArray *listArray;
}

@end

@implementation OpenCourseListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self creatCourseListView];
}

- (void)creatCourseListView{
    courseTable = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-64) style:UITableViewStylePlain];
    courseTable.dataSource = self;
    courseTable.delegate = self;
    [self.view addSubview:courseTable];
}

#pragma mark - request

- (void)requestCourseList{
    
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    hud.delegate = self;
    hud.labelText = @"加载中";
    
    NSString *module = @"openCourse";
    NSString *interface = @"videolist";
    
    NSString *timeString = [GetTime getTime];
    NSString *hashString = [[NSString stringWithFormat:@"%@/%@/key/%@/time/%@",module,interface,KEY,timeString] md5];
    NSString *urlString = [NSString stringWithFormat:@"%@/laravel/public/%@/%@/hash/%@/appid/1",URL2,module,interface,hashString];
    
    NSDictionary *parameter = @{@"time":timeString,@"typeid":self.courseType};
    
    //POST请求
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    [manager POST:urlString parameters:parameter success:^(AFHTTPRequestOperation *operation, id responseObject) {
        //
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];
        logdebug(@"%@",dic);
        [hud hide:YES];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        //
        [hud hide:YES];
    }];
}

#pragma mark - tab delegate

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 0;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 100;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    OpenCourseListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (cell == nil) {
        cell = [[OpenCourseListCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    }
    OpenCourseModel *model;
    
    [cell setValueWithModel:model];
    
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    OpenCourseModel *model = [listArray objectAtIndex:indexPath.row];
    OpenCourseInfoViewController *infoVC = [[OpenCourseInfoViewController alloc]init];
    infoVC.title = self.title;
    infoVC.videoId = model.videoId;
    [self.navigationController pushViewController:infoVC animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
